function ToPersonInfo() {
	nextView("personInfo.html");
}

function ToChangePassword() {
	nextView("changePassword.html");
}

//购物车
function ToCartRecord() {
	nextView("../payView/cartRecord.html");
}

//积分充值
function ToRechargePoint() {
	nextView("rechargePoint.html");
}

function ToIntegralStrategy() {
	nextView("integralStrategy.html");
}

function ToKuaidiOrderRecord() {
	nextView("kuaidiOrderRecord.html");
}

function ToHuishouOrderRecord() {
	nextView("huishouOrderRecord.html");
}

function ToCourenaoOrderRecord() {
	nextView("courenaoOrderRecord.html");
}

function ToGoumaiOrderRecord() {
	nextView("goumaiOrderRecord.html");
}

function ToWeixiuOrderRecord() {
	nextView("weixiuOrderRecord.html");
}

function ToLogin() {
	dataSave("loginType","personIndex");
	dataSave("userUuid","");
	dataSave("isLogined","");
	dataSave("openId", "");
	nextView("../../../page/OAuthGetCodeLogin.html");
}

$(function() {
	if(dataGet("openId") == "") {
		dataSave("loginType", "personIndex");
		nextView("../../../page/OAuthGetCodeLogin.html");
	}

	validSession();
	if(!dataGet('isLogined')){
		dataSave("openId", "");
		dataSave("loginType", "personIndex");
		nextView("../../../page/OAuthGetCodeLogin.html");
		return;
	}
	
	var userPoints = dataGet("userPoints");
	$('#myIntegral').html("您当前显示的积分是：" + userPoints + "分");
	$('#myName').html(dataGet("userName"));

	getUerDetails();
});

function getUerDetails() {
	var crusrUuid = dataGet("userUuid");

	var data = "&crusrUuid="+crusrUuid;
	var url = urlfile + "coreUser/views";

	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + XMLHttpRequest);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}else{
				dataSave("userName", data.data.crusrName);
				dataSave("userPhone", data.data.crusrMobile);
				dataSave("userPoints", data.data.crusrPoints);
				dataSave("userBalance", data.data.crusrBalance);
				dataSave("userSex", data.data.crusrGender);
				dataSave("userAddress", data.data.crusrAddress);
				dataSave("userBirthday", data.data.crusrBirthday); 

				if(data.data.headUuid){
					dataSave("headUuid", data.data.headUuid);
					$('#person-head').css("background","url(" + urlfile + "coreAttachment/image/get/" + data.data.headUuid + ")  no-repeat");
				}
			}
		}
	);
}

//签到领取积分
function ToIntegralSign(){
	var userPhone = dataGet("userPhone");
	var data = "&criglMobile="+userPhone;
	var url = urlfile + "coreUserRegister/register";
	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + data);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}else{
				//签到成功后更新用户积分数
				dataSave("userPoints", data.data);
				var userPoints = dataGet("userPoints");
				$('#myIntegral').html("您当前拥有积分：" + userPoints + "分");
				
				window.location.reload();   //刷新当前页面.
			}
		}
	);
}
